#include "VolumeRenderPCH.h"
#include "CustomGUI.h"
#include "DVRMethodsDef.h"

//**************************************************************************************************
//FUNCTION:
void CCustomGUI::initV()
{
	ResourceManager::registerSharedData("SamplingFactor", m_SamplingFactor);
	ResourceManager::registerSharedData("MinIntensity", m_MinIntensity);
	ResourceManager::registerSharedData("MaxIntensity", m_MaxIntensity);
	ResourceManager::registerSharedData("MinGradient", m_MinGradient);
	ResourceManager::registerSharedData("MaxGradient", m_MaxGradient);
	ResourceManager::registerSharedData("IsTFChanged", false);
}

//**************************************************************************************************
//FUNCTION:
void CCustomGUI::updateV()
{
#ifdef USING_ALL_METHODS
	if (InputManager::getKeyStatus(GLFW_KEY_G) == GLFW_PRESS)
		ResourceManager::updateSharedDataByName("DVRMethod", EDVRMethod::GENERAL_DVR);
	else if(InputManager::getKeyStatus(GLFW_KEY_L) == GLFW_PRESS)
		ResourceManager::updateSharedDataByName("DVRMethod", EDVRMethod::LINKED_LIST_OIT);
	else if (InputManager::getKeyStatus(GLFW_KEY_W) == GLFW_PRESS)
		ResourceManager::updateSharedDataByName("DVRMethod", EDVRMethod::WAVELET_OIT);
	else if (InputManager::getKeyStatus(GLFW_KEY_M) == GLFW_PRESS)
		ResourceManager::updateSharedDataByName("DVRMethod", EDVRMethod::MOMENT_BASED_OIT);
#endif // USING_ALL_METHODS

	IGUI::text(std::string("FileName: ") + ResourceManager::getSharedDataByName<std::string>("VolumeName"));

	IGUI::text(std::string("Width: ") + std::to_string(ResourceManager::getSharedDataByName<size_t>("VolumeWidth")));
	IGUI::sameLine();
	IGUI::text(std::string("Height: ") + std::to_string(ResourceManager::getSharedDataByName<size_t>("VolumeHeight")));
	IGUI::sameLine();
	IGUI::text(std::string("Depth: ") + std::to_string(ResourceManager::getSharedDataByName<size_t>("VolumeDepth")));

	IGUI::horizontalLine();

	IGUI::text("Transfer Func: ");
	IGUI::pushItemWidth(WINDOW_KEYWORD::getWindowWidth() * 0.05f);
	float MinSamplingFactor = 0.5f, MaxSamplingFactor = 5.0f;
	if (IGUI::sliderScalar("SamplingFactor", EDataType::DataType_Float, &m_SamplingFactor, &MinSamplingFactor, &MaxSamplingFactor, "%.3f"))
		ResourceManager::updateSharedDataByName("SamplingFactor", m_SamplingFactor);

	int MinMinIntensity = 0, MaxMinIntensity = m_MaxIntensity;
	if (IGUI::sliderScalar("##Intensity Min", EDataType::DataType_I32, &m_MinIntensity, &MinMinIntensity, &MaxMinIntensity))
	{
		ResourceManager::updateSharedDataByName("MinIntensity", m_MinIntensity);
		ResourceManager::updateSharedDataByName("IsTFChanged", true);
	}
	IGUI::sameLine();
	int MinMaxIntensity = m_MinIntensity, MaxMaxIntensity = 255;
	if (IGUI::sliderScalar("Intensity", EDataType::DataType_I32, &m_MaxIntensity, &MinMaxIntensity, &MaxMaxIntensity))
	{
		ResourceManager::updateSharedDataByName("MaxIntensity", m_MaxIntensity);
		ResourceManager::updateSharedDataByName("IsTFChanged", true);
	}

	int MinMinGradient = 0, MaxMinGradient = m_MaxGradient;
	if (IGUI::sliderScalar("##Gradient Min", EDataType::DataType_I32, &m_MinGradient, &MinMinGradient, &MaxMinGradient))
	{
		ResourceManager::updateSharedDataByName("MinGradient", m_MinGradient);
		ResourceManager::updateSharedDataByName("IsTFChanged", true);
	}
	IGUI::sameLine();
	int MinMaxGradient = m_MinGradient, MaxMaxGradient = 255;
	if (IGUI::sliderScalar("Gradient", EDataType::DataType_I32, &m_MaxGradient, &MinMaxGradient, &MaxMaxGradient))
	{
		ResourceManager::updateSharedDataByName("MaxGradient", m_MaxGradient);
		ResourceManager::updateSharedDataByName("IsTFChanged", true);
	}
	IGUI::popItemWidth();
;}
